/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.ourgame.tankgame.screen;

import de.lessvoid.nifty.Nifty;
import de.lessvoid.nifty.effects.EffectEventId;
import de.lessvoid.nifty.elements.Element;
import de.lessvoid.nifty.screen.Screen;
import de.lessvoid.nifty.screen.ScreenController;

/**
 *
 * @author echoff
 */
public class MainPage implements ScreenController {

    private Screen screen;
    private Nifty nifty;
    private boolean mute = false;

    public void bind(Nifty nifty, Screen screen) {
        this.nifty = nifty;
        this.screen = screen;
    }

    public void onStartScreen() {
    }

    public void onEndScreen() {
    }

    public void toggleMute() {
        System.out.println("toggleMute");
        this.mute = (!this.mute);
        if (this.mute) {
            this.screen.findElementByName("muteButton").setStyle("muteButtonSoundOff");
            this.screen.findElementByName("muteButton").startEffect(EffectEventId.onCustom);
        } else {
            this.screen.findElementByName("muteButton").setStyle("muteButtonSoundOn");
            this.screen.findElementByName("muteButton").startEffect(EffectEventId.onCustom);
        }
    }

    public void back() {
        this.nifty.gotoScreen("start");
    }

    public void next() {
        System.out.println("next!!___________________");
        showBackButton();
    }

    private void updateBackButtonVisibility() {
//        Element backButtonElement = this.screen.findElementByName("backButton");
//        if (this.pageIndex == 0) {
//            if (!this.lastPageWasActive) {
//                backButtonElement.setVisible(false);
//            }
//        } else if (this.pageIndex == 1) {
//            showBackButton();
//        }
//        Element currentPageElement = this.screen.findElementByName("curPage");
//        currentPageElement.startEffect(EffectEventId.onCustom);
//        ((TextRenderer) currentPageElement.getRenderer(TextRenderer.class)).setText(String.valueOf(this.pageIndex + 1) + " / " + this.pages.size());
    }

    private void showBackButton() {
        Element backButtonElement = this.screen.findElementByName("backButton");
        if (!backButtonElement.isVisible()) {
            backButtonElement.setVisible(true);
        }
    }
}
